package com.xl98.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xl98.entity.Appointment;
import com.xl98.mapper.AppointmentMapper;
import com.xl98.service.AppointmentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ls
 * @since 2020-05-15
 */
@Service
public class AppointmentServiceImpl extends ServiceImpl<AppointmentMapper, Appointment> implements AppointmentService {
    @Autowired
    private AppointmentMapper appointmentMapper;

    @Override
    public boolean insert(Appointment appointment) {
        if(appointmentMapper.insert(appointment)>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean update(Appointment appointment) {
        if(appointmentMapper.updateById(appointment)>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean delete(String id) {
        if(appointmentMapper.deleteById(id)>0){
            return true;
        }
        return false;
    }

    @Override
    public Appointment selectById(String id) {
        Appointment appointment = appointmentMapper.selectById(id);
        return appointment;
    }

    @Override
    public List<Appointment> selectByUserId(String userId) {
        QueryWrapper<Appointment> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        List<Appointment> list = appointmentMapper.selectList(queryWrapper);
        return list;
    }

    @Override
    public List<Appointment> selectByConsultantId(String consultantId) {
        QueryWrapper<Appointment> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("consultant_id",consultantId);
        List<Appointment> list = appointmentMapper.selectList(queryWrapper);
        return list;
    }

    @Override
    public List<Appointment> selectAll() {
        QueryWrapper<Appointment> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("id","%");
        List<Appointment> list = appointmentMapper.selectList(queryWrapper);
        return list;
    }
}
